import Vue from 'vue'
import VueRouter from 'vue-router'
import Amms from '../views/amms/Amms.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'amms',
    component: Amms,
    // beforeEnter: (to, form, next) => {
    //   console.log('to==', to);
    //   console.log('form==', form);
    //   if (null != sessionStorage.getItem('token')) {
    //     next('/workContent')
    //   } else {
    //     next('/login')
    //   }
    // },
    // redirect: 'login',
    children: [
      {
        path: '/workContent',
        name: 'workContent',
        component: () => import('../views/workContent/workContent.vue')
      },
      {
        path: '/user',
        name: 'user',
        component: () => import('../views/user/userInfo.vue'),
      },
      {
        path: '/memberConsume',
        name: 'memberConsume',
        redirect: 'memberConsume/valueStorageConsume',
        component: () => import('../views/memberConsume/MemberConsume.vue'),
        children: [
          {
            path: 'valueStorageConsume',
            name: 'valueStorageConsume',
            component: () => import('../views/memberConsume/components/ValueStorageConsume.vue')
          }
        ]
      },
      {
        path: '/memberDeposit',
        name: 'memberDeposit',
        redirect: 'memberDeposit/balanceRecharge',
        component: () => import('../views/memberDeposit/MemberDeposit.vue'),
        children: [
          {
            path: 'balanceRecharge',
            name: 'balanceRecharge',
            component: () => import('../views/memberDeposit/components/BalanceRecharge.vue')
          },
          {
            path: 'packageOpening',
            name: 'packageOpening',
            component: () => import('../views/memberDeposit/components/PackageOpening.vue')
          }
        ]
      },
      {
        path: '/memberManage',
        name: 'memberManage',
        redirect: 'memberManage/memberList',
        component: () => import('../views/memberManage/MemberManage.vue'),
        children: [
          {
            path: 'memberList',
            name: 'memberList',
            component: () => import('../views/memberManage/components/MemberList.vue'),
          }, {
            path: 'pendingMembers',
            name: 'pendingMembers',
            component: () => import('../views/memberManage/components/PendingMembers.vue')
          },{
            path: 'membershipTransfer',
            name: 'membershipTransfer',
            component: () => import('../views/memberManage/components/MembershipTransfer.vue')
          }, {
            path: 'memberAssets',
            name: 'memberAssets',
            component: () => import('../views/memberManage/components/MemberAssets.vue')
          }, {
            path: 'membershipFreeze',
            name: 'membershipFreeze',
            component: () => import('../views/memberManage/components/MembershipFreeze.vue')
          }, {
            path: 'membershipUpgrade',
            name: 'membershipUpgrade',
            component: () => import('../views/memberManage/components/MembershipUpgrade.vue')
          }
        ]
      },
      {
        path: '/financialManage',
        name: 'financialManage',
        redirect: 'financialManage/selfFundedDetails',
        component: () => import('../views/financialManage/FinancialManage.vue'),
        children: [
          {
            path: 'selfFundedDetails',
            name: 'selfFundedDetails',
            component: () => import('../views/financialManage/components/SelfFundedDetails.vue')
          }, {
            path: 'salesDetails',
            name: 'salesDetails',
            component: () => import('../views/financialManage/components/SalesDetails.vue')
          }
        ]
      },
      {
        path: '/systemOption',
        name: 'systemOption',
        redirect: 'systemOption/systemSettings',
        component: () => import('../views/systemOption/SystemOption.vue'),
        children: [
          {
            path: 'systemSettings',
            name: 'systemSettings',
            component: () => import('../views/systemOption/components/SystemSettings.vue')
          }
        ]
      },
      {
        path: '/services',
        name: 'services',
        redirect: 'services/recharge',
        component: () => import('../views/services/Services.vue'),
        children: [
          {
            path: 'recharge',
            name: 'recharge',
            component: () => import('../views/services/components/Recharge.vue')
          },
          {
            path: 'rechargeRecord',
            name: 'rechargeRecord',
            component: () => import('../views/services/components/RechargeRecord.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/Login.vue'),
  }
]

// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}


const router = new VueRouter({
  routes
})

export default router
